
package me.zhengjie.rest;

import me.zhengjie.annotation.Log;
import me.zhengjie.domain.AppDocCate;
import me.zhengjie.service.AppDocCateService;
import me.zhengjie.service.dto.AppDocCateQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @website https://el-admin.vip
* @author IQW
* @date 2022-07-18
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "文档分类管理")
@RequestMapping("/api/appDocCate")
public class AppDocCateController {

    private final AppDocCateService appDocCateService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
//    @PreAuthorize("@el.check('appDocCate:list')")
    public void exportAppDocCate(HttpServletResponse response, AppDocCateQueryCriteria criteria) throws IOException {
        appDocCateService.download(appDocCateService.queryAll(criteria), response);
    }

    @GetMapping(value = "/list")
    @Log("查询文档分类2")
    @ApiOperation("查询文档分类")
//    @PreAuthorize("@el.check('appDocCate:list')")
    public ResponseEntity<Object> queryAppDocCate(AppDocCateQueryCriteria criteria){
        return new ResponseEntity<>(appDocCateService.queryAll2(criteria),HttpStatus.OK);
    }


    @GetMapping
    @Log("查询文档分类")
    @ApiOperation("查询文档分类")
//    @PreAuthorize("@el.check('appDocCate:list')")
    public ResponseEntity<Object> queryAppDocCate(AppDocCateQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(appDocCateService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增文档分类")
    @ApiOperation("新增文档分类")
//    @PreAuthorize("@el.check('appDocCate:add')")
    public ResponseEntity<Object> createAppDocCate(@Validated @RequestBody AppDocCate resources){
        return new ResponseEntity<>(appDocCateService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改文档分类")
    @ApiOperation("修改文档分类")
//    @PreAuthorize("@el.check('appDocCate:edit')")
    public ResponseEntity<Object> updateAppDocCate(@Validated @RequestBody AppDocCate resources){
        appDocCateService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除文档分类")
    @ApiOperation("删除文档分类")
//    @PreAuthorize("@el.check('appDocCate:del')")
    public ResponseEntity<Object> deleteAppDocCate(@RequestBody Integer[] ids) {
        appDocCateService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}